import { router as routerConfig } from '../router'
import { routerhistory, template } from '../config.js'

routerConfig.forEach((item) => {
  item.component = () => import(`../pages/${item.page}.vue`)
})

const router = (base) => {
  base = base || template
  return {
    base: base,
    mode: routerhistory,
    routes: routerConfig,
  }
}

// 全局前置守卫
export function beforeEach(to, from, next) {
  console.log('beforeEach');
  next()
}
// 全局后置钩子
export function afterEach(to, from) {
  console.log('afterEach');
}
// 全局解析守卫
export function beforeResolve(to, from, next) {
  console.log('beforeResolve');
  next()
}

export default router
